<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="tabtop">
          <div v-for="(item, index) in contractTypelist" :key="index" @click="choose(item.id)">
            <div :class="currenindex == index ? 'active' : 'text'">
              {{ item.value }}
            </div>
          </div>
        </div>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <span v-show="!showCardNav">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </span>
            <span v-show="showCardNav">
              <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
            </span>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div v-if="currenindex == 0" class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px">站点名称</span>
                <el-input v-model="tableParam.station" style="width: 220px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px">
                <span style="margin-right: 12px">物料名称</span>
                <el-input v-model="tableParam.rawName" style="width: 220px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px">
                <span style="margin-right: 12px">供应商</span>
                <el-input v-model="tableParam.supplierName" style="width: 220px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
            </div>
            <div v-if="currenindex == 1" class="search">
              <span>
                <span style="margin-right: 12px">需求时间</span>
                <el-date-picker v-model="tableParam.createTime" type="datetime" placeholder="选择开始时间" style="width: 190px" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                <span style="padding: 0 20px">--</span>
                <el-date-picker v-model="tableParam.updateTime" type="datetime" placeholder="选择截止时间" style="width: 190px" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
              </span>
              <span style="margin-left: 24px">
                <span style="margin-right: 12px">原物料供应商</span>
                <el-input v-model="tableParam.carCompanyName" style="width: 220px" clearable />
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <div v-loading="tableLoading" class="card_info" :style="style">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark">
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :width="item.width" :fixed="item.label == '操作'?'right':false">
                  <template slot-scope="scope">
                    <div v-if="item.label == '状态'">
                      <span v-if="currenindex == 0" style="color: #808080">{{
                        scope.row.rawStatus == 0
                        ? "拒绝"
                        : scope.row.rawStatus == 1
                        ? "待确定"
                        : scope.row.rawStatus == 2
                        ? "已接受待提交计划"
                        : "已提交"
                        }}</span>
                      <span v-if="currenindex == 1" style="color: #808080">{{
                        scope.row.carStatus == 0
                        ? "拒绝"
                        : scope.row.carStatus == 1
                        ? "待确定"
                        : scope.row.carStatus == 2
                        ? "已接受待提交计划"
                        : "已提交"
                        }}</span>
                    </div>
                    <div v-else-if="item.label == '交货计划时间段'">
                      <span>{{ scope.row.startDeliveryTime }}--{{
                        scope.row.endDeliveryTime
                        }}</span>
                    </div>
                    <div v-else-if="item.label == '是否含运输'">
                      <span v-if="scope.row.transportStatus == 1" style="color: #00a754">是</span>
                      <span v-else style="color: #969799">否</span>
                    </div>
                    <div v-else-if="item.label == '操作'" style="display:flex; justify-content:center;">
                      <el-dropdown :hide-on-click="false" trigger="click">
                        <el-button v-if="scope.row.rawStatus != 1" size="mini" class="bottom_one">更多</el-button>
                        <el-dropdown-menu slot="dropdown" style="text-align: center">
                          <el-dropdown-item>
                            <div v-if="scope.row.rawStatus != 1&&currenindex == 0 && ButtonList.findIndex(res=>(res.buttonValue=='ZUIJIAJIHUA'))!==-1">
                              <el-button size="mini" style="margin:5px 0" class="bottom_one" @click="open(scope.row, 'planDialog')">追加计划</el-button>
                            </div>
                            <div v-if="currenindex == 1">
                              <el-button v-if="scope.row.rawStatus == 0&& ButtonList.findIndex(res=>(res.buttonValue=='ZHUANGPAI'))!==-1" style="margin:5px 0" size="mini" class="bottom_one" @click="open(scope.row, 'sendDialog')">转派</el-button>
                            </div>
                          </el-dropdown-item>
                          <el-dropdown-item v-if="ButtonList.some(res=>(res.buttonValue=='SHOUHUOCHAXUN'))">
                            <el-button style="margin:5px 0" size="mini" class="bottom_one" @click="open(scope.row, 'goodsDialog')">收货查询</el-button>
                          </el-dropdown-item>
                        </el-dropdown-menu>
                      </el-dropdown>
                    </div>
                    <span v-else>{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
          <div class="card_bottom">
            <div class="card_bottom_left">
              <div class="top_page_totle">总共{{ total }}条</div>
              <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="gettableData()"></el-pagination>
            </div>
            <div>
              <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
            </div>
          </div>
        </div>
      </el-main>
    </el-container>
    <!--追加计划-->
    <el-dialog v-dialogDrag :visible.sync="planDialog" width="1090px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">追加计划</span>
      <div>
        <el-form ref="refplanParams" :inline="true" label-width="110px" :model="planParams" :rules="rules1">
          <el-form-item>
            <span slot="label" style="color: #ff0000">原物料名称</span>
            <div style="width: 210px">{{ low.rawName }}</div>
          </el-form-item>
          <el-form-item prop="practiceNumer">
            <span slot="label" style="color: #ff0000">需求总量(吨)</span>
            <el-input-number v-model="planParams.practiceNumer" style="width:100px" :controls="false" :precision="0"></el-input-number>
          </el-form-item>
          <el-form-item prop="needDate">
            <span slot="label" style="color: #ff0000">需求日期</span>
            <el-date-picker v-model="planParams.needDate" type="date" value-format="yyyy-MM-dd 00:00:00" placeholder="选择日期"></el-date-picker>
          </el-form-item>
        </el-form>
        <div>
          <span class="dialog-title">原物料供应详情</span>
          <el-button size="mini" class="bottom_three" style="margin-left: 40px" @click="getplanlist()">获取计划</el-button>
          <el-button size="mini" class="bottom_all" style="margin-left: 12px" @click="addItem()">
            <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
            添加
          </el-button>
        </div>
        <div style="padding-top: 10px">
          <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="planTable" tooltip-effect="dark">
            <el-table-column label="合同编号" align="center">
              <template slot-scope="scope">
                <el-select v-if="!scope.row.isReadOnly" v-model="scope.row.contractId" :disabled='scope.row.isReadOnly?true:false' placeholder="请选择" style="width: 100%" @change="changeitem(scope.row)">
                  <el-option v-for="(item, index) in planData1" :key="index" :label="item.contractNo" :value="item.contractId"></el-option>
                </el-select>
                <span v-else>{{scope.row.contractNo}}</span>
              </template>
            </el-table-column>
            <el-table-column label="供应商" align="center" prop="supplierName"></el-table-column>
            <el-table-column label="份额" align="center" prop="supplierPercent"></el-table-column>
            <el-table-column label="原物料" align="center">
              <template slot-scope="scope">
                <el-select v-if='!scope.row.isReadOnly' v-model="scope.row.rawMaterialsId" placeholder="请选择" style="width:100%" @change="change1(scope.row)">
                  <el-option v-for="(item, index) in scope.row.list" :key="index" :label="item.productName+'_'+item.brand+'_'+item.specification" :value="item.productId"></el-option>
                </el-select>
                <span v-else>{{scope.row.rawMaterialsName}}</span>
              </template>
            </el-table-column>
            <el-table-column label="规格" align="center" prop="specification"></el-table-column>
            <el-table-column label="品牌" align="center" prop="brand"></el-table-column>
            <el-table-column label="是否含运输" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.transportStatus == 1" style="color: #00a754">是</span>
                <span v-else style="color: #969799">否</span>
              </template>
            </el-table-column>
            <el-table-column label="供应量" align="center">
              <template slot-scope="scope">
                <el-input-number v-model="scope.row.supplierNumber" style="width: 100%" :controls="false" :precision="0"></el-input-number>
              </template>
            </el-table-column>
            <el-table-column label="车辆外包合同" align="center" prop="carContractNo">
              <template slot-scope="scope">
                <span v-if="scope.row.transportStatus == 1">{{scope.row.carContractNo}}</span>
                <span v-else>
                  <el-select v-model="scope.row.carContractId" :disabled="scope.row.contractId?false:true" placeholder="请选择" style="width: 100%" @change="change2(scope.row)" @visible-change="getplanData1(scope.row)">
                    <el-option v-for="item in scope.row.planData2" :key="item.contractId" :label="item.contractNumber+'：'+item.cargo" :value="item.contractId"></el-option>
                  </el-select>
                </span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="left" width="120">
              <template slot-scope="scope">
                <el-button size="mini" class="bottom_two" @click="deleteItem(scope.$index)">
                  <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="planDialog = false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submitPlan()">提交审核</el-button>
      </span>
    </el-dialog>

    <!--收货查询-->
    <el-dialog v-dialogDrag :visible.sync="goodsDialog" width="1090px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">收货查询</span>
      <div>
        <el-form ref="refgoodsParams" :inline="true" label-width="100px" :model="goodsParams">
          <el-form-item>
            <span slot="label">收货站点</span>
            <el-input v-model="goodsParams.receiveStation" placeholder="请输入" style="width: 200px" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">物料名称</span>
            <el-input v-model="goodsParams.rawName" placeholder="请输入" style="width: 200px" clearable></el-input>
          </el-form-item>
          <el-form-item label-width="80px">
            <span slot="label">状态</span>
            <el-select v-model="goodsParams.receiveStatus" placeholder="请选择" style="width: 100px">
              <el-option v-for="(item, index) in arr2" :key="index" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(goodsParams.page = 1), getGoods()">查 询</el-button>
          <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="initGoods()">重 置</el-button>
        </el-form>
        <div style="padding-top: 10px">
          <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="goodsTable" tooltip-effect="dark">
            <el-table-column label="收货站点" align="center" prop="receiveStation"></el-table-column>
            <el-table-column label="库存仓" align="center" prop="repertory"></el-table-column>
            <el-table-column label="状态" align="center">
              <template slot-scope="scope">
                <span style="color: #969799">{{
                  arr2 | fromatTable(scope.row.receiveStatus, "itemName", "id")
                  }}</span>
              </template>
            </el-table-column>
            <el-table-column label="供应商名称" align="center" prop="supplier"></el-table-column>
            <el-table-column label="物料名称" align="center" prop="rawName"></el-table-column>
            <el-table-column label="物料规格" align="center" prop="specification"></el-table-column>
            <el-table-column label="货票量" align="center" prop="ticketNum"></el-table-column>
            <el-table-column label="一次过磅量" align="center" prop="firstWeight"></el-table-column>
            <el-table-column label="二次过磅量" align="center" prop="secondWeight "></el-table-column>
            <el-table-column label="扣减量" align="center" prop="deductionNum"></el-table-column>
            <el-table-column label="含水率" align="center" prop="moistureContent"></el-table-column>
            <el-table-column label="收货量" align="center" prop="receiveNum"></el-table-column>
            <el-table-column label="交货量照片" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.imgs" class="table_link" @click="show1(scope.row.imgs,'交货量照片')">查看</div>
              </template>
            </el-table-column>
            <el-table-column label="材质书" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.materialBookUrl" class="table_link" @click="show1(scope.row.materialBookUrl,'材质书照片')">查看</div>
              </template>
            </el-table-column>
            <el-table-column label="附件" align="center">
              <template slot-scope="scope">
                <div v-if="scope.row.accessoryUrl" class="table_link" @click="show1(scope.row.accessoryUrl,'附件照片')">查看</div>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" prop="remark"></el-table-column>
            <el-table-column label="交货车辆" align="center" prop="deliveryVehicl"></el-table-column>
            <el-table-column label="司机" align="center" prop="driver"></el-table-column>
            <el-table-column label="实际收货时间" align="center" prop="actualReceiveTime"></el-table-column>
            <el-table-column label="一次过磅量时间" align="center" prop="firstTime"></el-table-column>
            <el-table-column label="二次过磅量时间" align="center" prop="secondTime"></el-table-column>
            <el-table-column label="收货地点" align="center" prop="receiveStationSite"></el-table-column>
            <el-table-column fixed="right" label="操作" align="left" width="120">
              <template slot-scope="scope">
                <el-link v-if="scope.row.receiveStatus == 1" class="table_link" :underline="false" @click="open1(scope.row, 'goods1Dialog')">异常申报</el-link>
                <el-link v-if="scope.row.receiveStatus == 4" class="table_link" :underline="false" @click="open1(scope.row, 'goods2Dialog')">异常评价</el-link>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="dialog-pages">
          <div class="dialog_page_totle">总共{{ goodstotal }}条</div>
          <el-pagination :current-page.sync="goodsParams.page" :page-size="goodsParams.pageSize" layout="prev, pager, next, jumper" :total="goodstotal" @current-change="getGoods()"></el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="goodsDialog = false">关 闭</el-button>
      </span>
    </el-dialog>
    <!-- 异常申报 -->
    <el-dialog v-dialogDrag :visible.sync="goods1Dialog" width="600px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">异常评价</span>
      <div>
        <el-form ref="refgoods1Params" :rules="rules3" :inline="true" :model="goods1Params" label-width="110px">
          <el-form-item prop="evaluate">
            <span slot="label">评价内容</span>
            <el-input v-model="goods1Params.evaluate" :rows="3" resize="none" style="width: 370px;" type="textarea" placeholder="请输入" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="goods1Dialog = false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submitgoods1()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 异常评价 -->
    <el-dialog v-dialogDrag :visible.sync="goods2Dialog" width="580px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">异常评价</span>
      <div>
        <el-form ref="refgoods2Params" :inline="true" :model="goods2Params" label-width="110px">
          <el-form-item prop="evaluate" :rules="[
              { required: true, message: '请输入异常评价', trigger: 'blur' },
            ]">
            <span slot="label">异常现象</span>
            <el-input v-model="goods2Params.evaluate" type="textarea" :rows="5" resize="none" placeholder="请输入" style="width: 400px" maxlength="60" show-word-limit clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="goods2Dialog = false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submitgoods2()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 转派 -->
    <el-dialog v-dialogDrag :visible.sync="sendDialog" width="460px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">转派</span>
      <el-form ref="reffromDate" :rules="rules3" :inline="true" :model="sendDate" label-width="110px">
        <el-form-item>
          <span slot="label" style="color: #ff0000">车辆外包合同：</span>
          <span>{{ low.carContractNo }}_{{ low.supplierName }}</span>
        </el-form-item>
        <el-form-item prop="code">
          <span slot="label" style="color: #ff0000">站点编码</span>
          <el-select v-model="sendDate.carContractId" placeholder="请选择">
            <el-option v-for="(item, index) in arr1" :key="index" :label="item.contractNumber" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="sendDialog = false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submitsend()">提交审核</el-button>
      </span>
    </el-dialog>
    <!-- 查看图片 -->
    <ShowDetails :dialog="imgsDialog" :imgsText="imgsText" :imgList="imgList" :mp4List="mp4List" :fileList="fileList" @reset="reset"></ShowDetails>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import ShowDetails from '@/components/showdetails';
import {
  queryPage,
  Download,
  getListByraw,
  QueryPage2,
  applyException,
  evaluateException,
  getContractCarByCondition,
} from "@/api/GHnumber/demand.js";
import { getContracts } from "@/api/GHnumber/share.js";
import { getLotAllotsByStation } from "@/api/GHnumber/DSPplorder.js";
export default {
  mixins: [mixin],
  components: {
    ShowDetails
  },
  data() {
    return {
      imgsDialog: false,
      imgsText: '',
      imgList: [],
      mp4List: [],
      fileList: [],
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      DownloadURL: Download,
      /*表格数据*/
      table: [],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      contractTypelist: [
        { value: "原物料", id: 0 },
        { value: "车辆租赁", id: 1 },
      ],
      currenindex: 0,
      tableA: [
        { label: "原物料计划编码", width: "180", prop: "code", status: true },
        { label: "站点名称", width: "120", prop: "station", status: true },
        { label: "原料名称", width: "auto", prop: "rawName", status: true },
        { label: "规格", width: "120", prop: "specification", status: true },
        {
          label: "原物料合同编码",
          width: "180",
          prop: "contractNo",
          status: true,
        },
        {
          label: "原物料供应商",
          width: "120",
          prop: "supplierName",
          status: true,
        },
        { label: "是否含运输", width: "120", prop: "", status: true },
        { label: "计划供应量", width: "120", prop: "supplierNumber", status: true },
        { label: "累计交货量", width: "120", prop: "cumulant", status: true },
        { label: "需求时间", width: "135", prop: "needDate", status: true },
        {
          label: "车辆供应商",
          width: "140",
          prop: "carCompanyName",
          status: true,
        },
        {
          label: "运输车队联系电话",
          width: "120",
          prop: "carCompanyPhone",
          status: true,
        },
        { label: "协作单位", width: "120", prop: "cooperation", status: true },
        { label: "交货计划时间段", width: "260", prop: "", status: true },
        { label: "交货车次", width: "120", prop: "departure", status: true },
        { label: "状态", width: "120", prop: "", status: true },
        { label: "操作", width: "100", prop: "", status: true },
      ],
      tableB: [
        {
          label: "车辆租赁计划编码",
          width: "180",
          prop: "code",
          status: true,
        },
        { label: "站点", width: "120", prop: "station", status: true },
        {
          label: "车辆租赁合同编号",
          width: "180",
          prop: "carContractNo",
          status: true,
        },
        { label: "供应商", width: "120", prop: "carCompanyName", status: true },
        { label: "需求时间", width: "120", prop: "needDate", status: true },
        { label: "接货地", width: "120", prop: "loadingPort", status: true },
        { label: "收货地", width: "120", prop: "placeReceipt", status: true },
        { label: "交货计划时间段", width: "260", prop: "", status: true },
        { label: "交货车次", width: "120", prop: "departure", status: true },
        { label: "状态", width: "100", prop: "", status: true },
        { label: "操作", width: "100", prop: "", status: true },
      ],
      low: {},
      childlow: {},
      /*追加计划*/

      planDialog: false,
      planParams: {},
      planTable: [],
      rules1: {
        needDate: [
          { required: true, message: "请选择时间", trigger: "change" },
        ],
        practiceNumer: [
          { required: true, message: "请输入需求量", trigger: "blur" },
        ],
      },
      planData1: [],
      planData2: [],
      /* 收货查询*/
      goodsDialog: false,
      goodsTable: [],
      goodsParams: {
        page: 1,
        pageSize: 12,
      },
      goodstotal: 0,
      arr2: [
        { itemName: "运输中", id: 1 },
        { itemName: "检验中", id: 2 },
        { itemName: "卸料中", id: 3 },
        { itemName: "内部确认中", id: 4 },
        { itemName: "外部确认中", id: 5 },
        { itemName: "已接受", id: 6 },
        { itemName: "退回", id: 7 },
      ],
      /*异常申报*/
      goods1Dialog: false,
      goods1Params: {
        processModeId: 0,
      },
      rules3: {
        evaluate: [{ required: true, message: "请输入", trigger: "blur" }],
      },
      arr5: [
        { itemName: "按车次进行处罚定金", id: 1 },
        { itemName: "按照计量总量的百分比进行单价扣减", id: 2 },
        { itemName: "先收取后约谈商定条件", id: 3 },
      ],
      /*异常评价*/
      goods2Dialog: false,
      goods2Params: {},
      /*转派*/
      sendDialog: false,
      sendDate: {},
      rules4: {
        carContractId: [
          { required: true, message: "请选择车辆外包合同", trigger: "change" },
        ],
      },
      arr1: [],
    };
  },
  watch: {
    currenindex: {
      handler() {
        this.$data.tableParam = this.$options.data().tableParam;
        switch (this.currenindex) {
          case 0: {
            this.table = this.tableA;
            this.tableParam = {
              ...this.tableParam,
              station: "",
              rawName: "",
              supplierName: "",
            };
            this.gettableData();
            return;
          }
          case 1: {
            this.table = this.tableB;
            this.tableParam = {
              ...this.tableParam,
              transportStatus: 0,
              carCompanyName: "",
              createTime: "",
              updateTime: "",
            };
            this.gettableData();
            return;
          }
        }
      },
      deep: false, //是否深度监听，true为是，默认为false
      immediate: true, //immediate表示在watch中首次绑定的时候，是否执
    },
  },
  /*
   *copy(data)深拷贝数据,返回拷贝完的数据
   *gettableData获取列表数据
   *load下载
   *SortNum保持序列号
   * UpdateOrDelete禁用，启用，删除
   * submitFromDate保存更新数据
   */
  methods: {
    change1(item) {
      let data = item.list.find(
        (res) => res.productId == item.rawMaterialsId
      );
      item.rawId = data.productId;
      item.rawName = data.productName;
      item.brand = data.brand;
      item.specification = data.specification;
      item.carContractId = '';
      item.carContractNo = '';
      item.carCompanyId = '';
      item.carCompanyName = '';
    },
    /**看图*/
    show1(file, text) {
      let items = file ?.split(",").map(res => ('/file/' + res))
      this.imgList = items.filter(res => (res.includes('type=img')))
      this.mp4List = items.filter(res => (res.includes('type=mp4')))
      this.fileList = items.filter(res => (res.includes('type=file')))
      this.imgsText = text
      this.imgsDialog = true
    },
    reset(key) {
      this[key] = false;
    },
    /**查询当前原物料合同的车辆外包合同 */
    getplanData1(row) {
      getContractCarByCondition({ contractId: row.contractId, rawId: this.low.rawId, stationId: this.low.stationId }).then((res) => {
        if (res.data.length > 0) {
          row.planData2 = res.data
        } else {
          this.$message({
            message: "车辆外包合同空！",
            type: "warning",
          });
          row.planData2 = []
        }
        this.$forceUpdate()
      })
    },
    init() {
      /*重置数据*/
      this.$data.tableParam = this.$options.data().tableParam;
      if (this.currenindex == 1) {
        this.tableParam.transportStatus = 0;
      }
      this.gettableData();
    },
    choose(num) {
      this.currenindex = num;
    },
    /*打开弹窗*/
    open(low, key) {
      this.low = low;
      if (key == "sendDialog") {
        getListByraw({ contractTypeId: "2" }).then((res) => {
          this.arr1 = res.data;
          this.$data.sendDate = this.$options.data().sendDate;
          this[key] = true;
        });
        return;
      }
      if (key == "planDialog") {
        this.planTable = [];
        this.planParams = {};
        this[key] = true;
        setTimeout(() => {
          this.$refs.refplanParams.clearValidate();
        }, 10);
        this.planParams.dataType = 2;
        this.planParams.stationId = low.stationId;
        this.planParams.station = low.station;
        this.planParams.materials = low.rawName;
        this.planParams.materialsId = low.rawNameId;
        this.planParams.companyId = low.companyId;
        this.planParams.practiceNumer = low.supplierNumber - low.actualNumber
        this.initContractList(low);
        return;
      }
      if (key == "goodsDialog") {
        this[key] = true;
        this.initGoods();
        return;
      }
    },
    /**
     * @Description: 点击追加计划，通过
     * @Param: 
     * @Author: wangwangwang
     */
    initContractList(data) {
      /**
       * @Description: 通过站点和原物料获取合同号
       * @Param: 
       * @Author: wangwangwang
       */
      const params = {
        id: data.rawNameId,
        stations: data.stationId,
      }
      getContracts(params).then(res => {
        if (res.code === 1001) {
          if (!res.data.length) {
            this.$message.warning('合同编号为空');
            return;
          }
          this.planData1 = res.data;
        }
      })
    },
    open1(low, key) {
      this.childlow = low;
      this[key] = true;
      if (key == "goods2Dialog") {
        this.goods2Params = this.$options.data().goods2Params;
        this.goods2Params.evaluate = low.evaluate;
      } else {
        this.goods1Params = this.$options.data().goods1Params;
      }
    },
    /*追加计划*/
    getplanlist() {
      getLotAllotsByStation({
        stationId: this.low.stationId,
        rawId: this.low.rawNameId,
      }).then((res) => {
        if (res.code === 1001) {
          const newData = res.data.map(item => ({ ...item, isReadOnly: true, supplierName: item.supplier, supplierPercent: item.lotNum, transportStatus: item.isCarriage, supplierNumber: this.planParams.practiceNumer * item.lotNum * 0.01, rawName: item.rawMaterialsName }));
          this.planTable = newData;
        }
      });
    },
    addItem() {
      let item = {
        contractId: "",
        contractNo: "",
        supplierId: "",
        supplierName: "",
        rawId: "",
        rawName: "",
        supplierPercent: "",
        transportStatus: null,
        supplierNumber: "",
        carContractId: "",
        carContractNo: "",
        carCompanyId: "",
        carCompanyName: "",
        specification: "",
        brand: "",
      };
      this.planTable.push(item);
    },
    deleteItem(index) {
      this.planTable.splice(index, 1);
    },
    changeitem(item) {
      let data = this.planData1.find(
        (res) => res.contractId == item.contractId
      );
      console.log(JSON.parse(JSON.stringify(data)))
      item.contractNo = data.contractNo;
      item.list = data.list;
      item.companyId = data.companyId;
      item.company = data.company;
      item.supplierId = data.supplierId;
      item.supplierName = data.supplier;
      item.transportStatus = data.isCarriage;
      item.rawMaterialsId = '';
      item.specification = '';
      item.brand = '';
      item.carContractNo = '';
      item.carCompanyId = '';
      item.carCompanyName = '';
      item.supplierNumber = '';
      item.planData2 = []
      item.carContractId = '';
    },
    change2(item) {
      let data = item.planData2.find((res) => res.contractId == item.carContractId);
      console.log(item);
      item.carContractNo = data.contractNumber;
      item.carCompanyId = data.supplierId;
      item.carCompanyName = data.supplierName;
    },
    submitPlan() {
      this.planParams.list = this.planTable;
      let _this = this;
      _this.$refs.refplanParams.validate((valid) => {
        if (valid) {
          if (_this.planParams.list.length == 0) {
            _this.$message({
              message: "警告哦，请至少添加一条计划",
              type: "warning",
            });
            return;
          }
          if (!_this.planParams.list.every((v) => {
            if (v.transportStatus == 1) {
              if (v.contractId != '' && v.rawMaterialsId != '') {
                return true
              } else {
                return false
              }
            } else {
              if (v.contractId != '' && v.rawMaterialsId != '' && v.carContractNo != '') {
                return true
              } else {
                return false
              }
            }
          })) {
            _this.$message({
              message: "其检查表格数据是否填写完整！",
              type: "warning",
            });
            return
          }
          let sizeNumber = 0
          _this.planParams.list.forEach((v) => {
            sizeNumber = sizeNumber + Number(v.supplierNumber)
          })
          if (sizeNumber > this.planParams.practiceNumer) {
            _this.$message({
              message: "警告哦，供应量不能大于需求总量!",
              type: "warning",
            });
            return;
          }
          const copyData = JSON.parse((JSON.stringify(_this.planParams)));
          copyData.list = JSON.stringify(copyData.list);
          _this.$router.push({ name: 'AddOrder', query: { ...copyData, type: 1 } })
        } else {
          return false;
        }
      });
    },
    /*收货查询*/
    initGoods() {
      this.goodsParams = this.$options.data().goodsParams;
      this.goodsParams.rawNeedId = this.low.id;
      this.getGoods();
    },
    getGoods() {
      this.goodsParams.rawNeedId = this.low.id;
      QueryPage2(this.goodsParams).then((res) => {
        this.goodsTable = res.data.data;
        this.goodstotal = res.data.totalRows;
      });
    },
    /*异常申报*/
    submitgoods1() {
      this.$refs.refgoods1Params.validate((valid) => {
        if (valid) {
          this.goods1Params.consignmentId = this.childlow.id;
          this.goods1Params.type = 1;
          this.goods1Params.processMode =
            this.goods1Params.processModeId == 0 ? "退货" : "条件接收";
          this.goods1Params.acceptableConditings = this.$fromatTable(
            this.arr5,
            this.goods1Params.acceptableConditingsId,
            "id",
            "itemName"
          );
          applyException(this.goods1Params).then(() => {
            this.goods1Dialog = false;
            this.getGoods();
          });
          this.console(this.goods1Params);
        } else {
          return false;
        }
      });
    },
    /*异常评价*/
    submitgoods2() {
      this.goods2Params.id = this.childlow.id;
      evaluateException(this.goods2Params).then(() => {
        this.goods2Dialog = false;
      });
    },
    /*转派*/
    submitsend() {
      let key = this.arr1.find((res) => res.id == this.sendDate.carContractId);
      this.sendDate.id = this.low.id;
      this.sendDate.carContractNo = key.contractNumber;
      this.sendDate.carCompanyId = key.supplierId;
      this.sendDate.carCompanyName = key.supplierName;
      this.sendDate.carCompanyPhone = key.phone;

      this.$router.push({ name: 'CarTransfer', query: { ...this.sendDate, type: 1, station: this.low.station, supplierName: this.low.supplierName, rawName: this.low.rawName } });
      // carRedeploy(this.sendDate).then(() => {
      //   this.sendDialog = false;
      //   this.gettableData();
      // });
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog-pages {
  @include discen_al;
  padding-top: 10px;
}
.dialog-title {
  font-size: 16px;
  font-weight: bold;
  padding-right: 40px;
}
.el-input,
.el-select {
  width: 240px;
}
.table_link {
  margin: 0 10px;
  color: $bg_color;
}

.table_link:hover {
  opacity: 0.8;
}
.tabtop {
  width: 381px;
}
</style>
